package com.ppl.server.modules;

import akka.serialization.JSerializer;
import com.google.inject.AbstractModule;
import com.ppl.server.cache.BinaryJedisPool;
import com.ppl.server.cache.CachingProvider;
import com.ppl.server.cache.jedis.JedisCachingProvider;
import com.ppl.server.serializers.ProtostuffRuntimeSerializer;
import com.typesafe.config.ConfigFactory;


/**
 * User: Vincent
 * Date: 11/14/12
 * Time: 1:04 PM
 */
public class CacheModule extends AbstractModule {

    @Override
    protected void configure() {

        com.typesafe.config.Config config = ConfigFactory.load();
        String host = config.getString("cache.jedis.server.host");
        int port = config.getInt("cache.jedis.server.port");

        if (host == null) {
            host = "127.0.0.1";
        }
        bind(BinaryJedisPool.class).toInstance(new BinaryJedisPool(host, port));
        bind(CachingProvider.class).to(JedisCachingProvider.class).asEagerSingleton();
        bind(JSerializer.class).to(ProtostuffRuntimeSerializer.class).asEagerSingleton();
    }
}
